<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'推广组列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'type'=>0);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('tuilog',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['statustitle']=$this->tuilog_status[$item['status']];	
			$item['starttime']=$item['starttime']?date('Y-m',$item['starttime']):'';
			$item['endtime']=$item['endtime']?date('Y-m',$item['endtime']):'';
			$item['succtime']=$item['succtime']?date('Y-m',$item['succtime']):'';
			$item['istui']=pdo_count('jy_newcar_order',array('uniacid'=>$_SESSION['uniacid'],'tuilogid'=>$item['id']));
			$this->model('model')->uptuiqi($item['id']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page']=$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里购车合伙人推广组！</red>','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'id','title'=>'推广组ID','type'=>'string'),
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			//array('name'=>'lastqi','title'=>'剩余月份','type'=>'string'),
			array('name'=>'istui','title'=>'已推广数量','type'=>'string'),
			array('name'=>'starttime','title'=>'开始时间','type'=>'string'),
			array('name'=>'succtime','title'=>'完成时间','type'=>'string'),
			array('name'=>'endtime','title'=>'结束时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			//array('type'=>'href','op'=>'yufee','title'=>'查看分期奖励'),
			array('type'=>'href','op'=>'orderfee','title'=>'查看推广记录'),
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['status']=$this->tuilog_status;
	exi($return);
}
if($_RQ['op']=='orderfee'){	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'buytype'=>0);
	if($_RQ['id']){
		$params['tuilogid']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['ordersn']){
		$params['ordersn like']='%'.trim($_RQ['ordersn']).'%';
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['agent']=cfc('core')->member_show($item['agent_id']);
			$item['detail']='/commission/list/ordersn='.$item['ordersn'];
			$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
			if($orderid){
				$item['isgoods']=1;
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page']=$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：只有存在上级，或者支持内购（属于分销商），才会产生佣金！</br>非必要，不建议删除记录，怕数据异常！</red>','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'购车人','type'=>'member'),
			array('name'=>'agent','title'=>'推荐人','type'=>'member'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'price','title'=>'订单金额','type'=>'string'),
			array('name'=>'carprice','title'=>'车价','type'=>'string'),
			array('name'=>'qinum','title'=>'基数','type'=>'string'),
			array('name'=>'qifee','title'=>'共奖励','type'=>'string'),
			array('name'=>'ispay','title'=>'支付状态','type'=>'radio','options'=>'ispay'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			//array('type'=>'modal','op'=>'goods','title'=>'订单商品','show'=>array('isgoods'=>1)),
			//array('type'=>'href','name'=>'detail','title'=>'明细'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'ordersn','title'=>'订单号'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['ispay']=array('未支付','已支付');
	exi($return);
}
if($_RQ['op']=='yufee'){	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$params['tuilogid']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	if($_RQ['status']){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('yufee',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page']=$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里显示所有分期！</red>','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'price','title'=>'分期金额','type'=>'string'),
			array('name'=>'remark','title'=>'描述','type'=>'string'),
			array('name'=>'year','title'=>'年份','type'=>'string'),
			array('name'=>'month','title'=>'月份','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			//array('type'=>'href','name'=>'detail','title'=>'明细'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'ordersn','title'=>'订单号'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		),
	);
	$return['htmls']=$htmls;
	$return['status']=$this->yufee_status;
	exi($return);
}
if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_newcar_tuilog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_newcar_tuilog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>